# Modul for common entries in Preferences and Project Attributes

from etgui import *
from PageLayout import *
from AllListEditors import GeneralListEditor,ArrayEditor,IncludeDirectivesEditor

def MakeItemIgnoreDirs(model,path):
	list_editor=GeneralListEditor(model,path,"Ignore Directories",':')
	edit_button=ActionButton("Edit...",action=list_editor)
	field=PotTextField(path)
	AddSplitFieldTip(field,':')
	return [
		"Ignore Directories",FieldWithButtonLayout(field,edit_button)
	]

def MakeItemTabSize(model,path):
	return [
		"Tab Size",PotGuiIntField(path,IntField(-1,4,0,1024))
	]

def MakeItemUseMakeSupport(model,path):
	return PotGuiToggleButton(path,"Use SNiFF+ Make Support")

def MakeItemMakeCommand(model,path):
	return [
		"Make Command",PotTextField(path)
	]

def MakeItemHelpTarget(model,path):
	return [
		"General Targets",PotTextField(path)
	]

def MakeStringListEditor(model,path,label,new_item="New"):
	list_editor=GeneralListEditor(model,path,label)
	list_editor.new_item=new_item
	edit_button=ActionButton("Edit...",action=list_editor)
	field=PotTextField(path)
	AddSplitFieldTip(field," ")
	return [
		label,FieldWithButtonLayout(field,edit_button)
	]
def MakeSplitStringListEditor(model,path,label,new_item="New",editor=ArrayEditor):
	list_editor=editor(model,path,label)
	list_editor.new_item=new_item
	edit_button=ActionButton("Edit...",action=list_editor)
	tf=TextField(-1,gTextFieldLen)
	field= PotGuiSplitTextField(path,tf,' ')
	AddSplitFieldTip(field," ")
	return [
		label,FieldWithButtonLayout(field,edit_button)
	]
def MakeSplitIncludeListEditor(model,path,label,new_item="New"):
	return MakeSplitStringListEditor(model,path,label,new_item,IncludeDirectivesEditor)

def MakeItemIncludeDirectives(model,path):
	gen_button=PotGuiActionButton("PSEUDO.Action.GenIncludeMacro","Generate...")
	list_editor=ArrayEditor(model,path,"Include Directive(s)")
	list_editor.new_item="-I"
	edit_button=ActionButton("Edit...",action=list_editor)
	tf=TextField(-1,gTextFieldLen)
	field= PotGuiSplitTextField(path,tf,' ')
	AddSplitFieldTip(field," ")
	return [	
		"",Filler(gPointSectionGap),
		"Include Directive(s)",FieldWithButtonLayout(field,edit_button,gen_button)
	]
 
def MakeItemAdditionalIncludeDirectives(model,path):
	list_editor=GeneralListEditor(model,path,"Include Directive(s)")
	edit_button=ActionButton("Edit...",action=list_editor)
	field=PotTextField(path)
	AddSplitFieldTip(field," ")
	return [
		"Additional",FieldWithButtonLayout(field,edit_button)
	]

def MakeItemRecursiveMakeDirs(model,path):
	gen_button=PotGuiActionButton("PSEUDO.Action.GenSubDirs","Generate...")
	list_editor=GeneralListEditor(model,path,"Recursive Make Dir(s)")
	edit_button=ActionButton("Edit...",action=list_editor)
	field=PotTextField(path)
	AddSplitFieldTip(field," ")
	return [
		"Recursive Make Dir(s)",FieldWithButtonLayout(field,edit_button,gen_button)
	]

def MakeItemConfigurationFiles(model,path):
	return [
		"Parser Configuration File(s)",PotGuiFileSelector(path,gTextFieldLen,"Config File")
	]

def MakeItemPreprocessorDirectives(model,path):
	list_editor=GeneralListEditor(model,path,"Preprocessor Directive(s)")
	edit_button=ActionButton("Edit...",action=list_editor)
	field=PotTextField(path)
	AddSplitFieldTip(field," ")
	return [
		"Preprocessor Directive(s)",FieldWithButtonLayout(field,edit_button)
	]

def MakeItemVersionTool(model,path):
	versionTool=PotGuiPopupButton(path)
	def UpdateVCPopup(model,path='',popup=versionTool):
		popup.RemoveAllItems()
		popup.AddItem("<None>",None)
		itemsList=Cast(model).GetIndex("VCS_INTERFACE")
		if itemsList:
			itemsList.sort()
			for v in itemsList:
				popup.AddItem(v,v)   # (display, model)
	model.AddModelObserver(UpdateVCPopup,"VCS_INTERFACE")
	return [
		"Version Tool",MakeFieldLayout(versionTool)
	]

def MakeItemUseParserComments(model,path):
	return PotGuiToggleButton(path,"Use Parser Comments for Syntax Highlighting")
 
def MakeItemAPIPositions(model,path):
	return PotGuiToggleButton(path,"Extended Symtab API Positioning")

